package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import com.itheima.service.impl.EmpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result findAll(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String name, Integer gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin ,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        //PageResult pageResult = empService.findAll(page, pageSize);
        PageResult pageResult = empService.findAll(page,pageSize,name,gender,begin,end);
        return Result.success(pageResult);
    }

    /*@PostMapping
    public Result add(@RequestBody Emp emp){

    }*/

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);
        return Result.success();
    }
    @PutMapping
    public Result add(@RequestBody Emp emp){
        empService.add(emp);
        return Result.success();
    }
}
